﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.10.2.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->

<title>維護環境</title>

<script type="text/javascript">

var tmp="";

$(document).ready(function() {
	init("env.html");
	$("#gd").jqGrid({
		url:'QueryEnv',
		datatype: "json",
		postData:{fc:"dafsfd",subsysId:"fOrder"},
		type: "post",
		colNames:["環境ID","環境名稱"],
	   	//colNames:["環境ID","環境名稱","Web Console","自身層級","預先部署"],
	   	colModel:[{	/*	環境ID	*/
	   			name:"envId",
	   			index:"envId",
	   			editable:true,
	   			editrules:{ required:true }
	   		}, {	/*	環境名稱	*/
	   			name:"envName",
	   			index:"envName",
	   			editable:true,
	   			editrules:{ required:true }
	   		}/* ,{
	   	       name:'webConsole',index:'webConsole',resizable:true,   
	   	       align:"left",sorttype:"text",editable:true,edittype:"select" ,editrules:{required:true}
	   	    }, {	//	自身層級	
	   			name:"selfClass",
	   			formatter:'integer', formatoptions:{defaultValue: '1'},
	   			editable:true,
	   			editrules:{ required:true }
	   		}, {	//	預先部署	
	   			name:"preClass",
	   			formatter:'integer', formatoptions:{defaultValue: '0'},
	   			editable:true,
	   			editrules:{ required:true }
	   		} */
	   	],
	   	rowNum: 6,
	   	forceFit: true,
	   	pager: "#pager",
		rownumbers: true,
	   	viewrecords: true,	
		caption: "維護環境"
	}).jqGrid("navGrid","#pager",{add:true,edit:true,del:true,search:false,refresh:false},
		{	
			/* Edit
				按下送出後要完成下列功能
				1. 畫面更新為新輸入的資料
				2. 後端更改新值成功 
			*/
			url: "ManipulateGridEnv",
			mtype: "POST",
			/* afterShowForm : function(formid) {
				var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
				sel_id = $("#gd").jqGrid('getCell', sel_id, 'webConsole');
				$.post('QueryWCL',{fc:'2',bssId:$("table#parTable #bss option:selected").val(), subsysId: $("table#parTable #subsys option:selected").val() },function(reses) {
					$("select.FormElement option").remove();
					$.each( reses, function(i, res) {
						tmp = "";
						if ( res.strA == sel_id) { tmp="SELECTED"; }
						$("select.FormElement").append("<option id='"+res.intA+"' "+tmp+" >"+res.strA+"</option>");	
					});
				},"JSON");
			}, */
			
			editData:{
				subsysId: function() { return 'fOrder';/* $("table#parTable #subsys option:selected").val(); */ },
				//webconsole: function() { return $("select.formelement option:selected").attr("id"); },
				empId: function() { return $.cookie("empId"); }
				
				/* bssid: function() { return $("table#partable #bss option:selected").val();},
				subsysid: function() { return $("table#partable #subsys option:selected").val(); },
				webconsole: function() { return $("select.formelement option:selected").attr("id"); },
				currentuser: function() { return $.cookie("empid"); } */
			}		
		},
		{	// Add
			url: "ManipulateGridEnv",
			mtype: "POST",
			/* afterShowForm : function(formid) {
				var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
				sel_id = $("#gd").jqGrid('getCell', sel_id, 'webConsole');
				$.post('QueryWCL',{fc:'2',bssId:$("table#parTable #bss option:selected").val(), subsysId: $("table#parTable #subsys option:selected").val() },function(reses) {
					$("select.FormElement option").remove();
					$.each( reses, function(i, res) {
						tmp = "";
						if ( res.strA == sel_id) { tmp="SELECTED"; }
						$("select.FormElement").append("<option id='"+res.intA+"' "+tmp+" >"+res.strA+"</option>");	
					});
				},"JSON");
			}, */
			editData: {
				//bssId: function() { return $("table#parTable #bss option:selected").val();},
				subsysId: function() { return 'fOrder';/* $("table#parTable #subsys option:selected").val(); */ },
				empId: function() { return $.cookie("empId"); }
			}
		},
		{	// Delete
			url: "ManipulateGridEnv",
			mtype: "POST",
			delData: { 
				//bssId: function() { return $("table#parTable #bss option:selected").val();},
				envId: function() {
					var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
					return $("#gd").jqGrid('getCell', sel_id, 'envId');
				},
				subsysId: function() { return 'fOrder';/* $("table#parTable #subsys option:selected").val(); */ },
				empId: function() { return $.cookie("empId"); }
			}
	});
}).tooltip();
</script>

</head>
<body>
	<div id="header"></div>
	<p>
	<img src="pic/env.png" > 
	<p><p> 
	<table id="gd"></table>
	<div id="pager"></div>
</body>
</html>